package com.ruoyi.system.service.analysis.impl;

import com.ruoyi.system.domain.analysis.*;
import com.ruoyi.system.mapper.analysis.UserAnalysisMapper;
import com.ruoyi.system.service.analysis.IUserAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserAnalysisServiceImpl implements IUserAnalysisService {

    @Autowired
    private UserAnalysisMapper userAnalysisMapper;

    @Override
    public List<UserTierStats> getUserTierDistribution() {
        return userAnalysisMapper.selectUserTierDistribution();
    }

    @Override
    public List<BehaviorRadarData> getBehaviorRadarData() {
        return userAnalysisMapper.selectBehaviorRadarData();
    }

    @Override
    public List<TimeTrendData> getTimeTrendData(int months) {
        return userAnalysisMapper.selectTimeTrendData(months);
    }

    @Override
    public List<WatchDurationDist> getWatchDurationDistribution() {
        return userAnalysisMapper.selectWatchDurationDistribution();
    }

    @Override
    public List<CompletionSatisfaction> getCompletionSatisfactionData() {
        return userAnalysisMapper.selectCompletionSatisfactionData();
    }

    @Override
    public Map<String, Object> getDashboardData() {
        Map<String, Object> result = new HashMap<>();
        result.put("userTier", getUserTierDistribution());
        result.put("behaviorRadar", getBehaviorRadarData());
        result.put("timeTrend", getTimeTrendData(6));
        result.put("watchDuration", getWatchDurationDistribution());
        result.put("completionSatisfaction", getCompletionSatisfactionData());
        return result;
    }

    @Override
    public Map<String, Object> getEnhancedDashboardData() {
        Map<String, Object> result = new HashMap<>();
        result.put("userPyramid", getUserPyramidData());
        result.put("threeDimensional", getThreeDimensionalData());
        result.put("paymentFunnel", getPaymentFunnelData());
        result.put("watchHeatmap", getWatchHeatmapData());
        result.put("contentPreference", getContentPreferenceData());
        result.put("userLifecycle", getUserLifecycleData());
        result.put("revenueContribution", getRevenueContributionData());
        return result;
    }

    @Override
    public List<Map<String, Object>> getUserPyramidData() {
        return userAnalysisMapper.selectUserPyramidData();
    }

    @Override
    public List<Map<String, Object>> getThreeDimensionalData() {
        return userAnalysisMapper.selectThreeDimensionalData();
    }

    @Override
    public List<Map<String, Object>> getPaymentFunnelData() {
        return userAnalysisMapper.selectPaymentFunnelData();
    }

    @Override
    public List<Map<String, Object>> getWatchHeatmapData() {
        return userAnalysisMapper.selectWatchHeatmapData();
    }

    @Override
    public List<Map<String, Object>> getContentPreferenceData() {
        return userAnalysisMapper.selectContentPreferenceData();
    }

    @Override
    public List<Map<String, Object>> getUserLifecycleData() {
        return userAnalysisMapper.selectUserLifecycleData();
    }

    @Override
    public List<Map<String, Object>> getRevenueContributionData() {
        return userAnalysisMapper.selectRevenueContributionData();
    }

    @Override
    public List<Map<String, Object>> getActorPreferences() {
        return userAnalysisMapper.getActorPreferences();
    }

    @Override
    public List<Map<String, Object>> getRFMAnalysis() {
        return userAnalysisMapper.getRFMAnalysis();
    }
}